/**
 * 
 */
package gemini.basic.batch;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.JobListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Listener for all jobs.
 *
 */
public class GmnGlobalJobListener implements JobListener {
    private final Logger logger = LoggerFactory.getLogger(GmnGlobalJobListener.class);

    /* (non-Javadoc)
     * @see org.quartz.JobListener#getName()
     */
    @Override
    public String getName() {
        return "GmnGlobalJobListener";
    }

    /* (non-Javadoc)
     * @see org.quartz.JobListener#jobToBeExecuted(org.quartz.JobExecutionContext)
     */
    @Override
    public void jobToBeExecuted(JobExecutionContext context) {
        // TODO Auto-generated method stub

    }

    /* (non-Javadoc)
     * @see org.quartz.JobListener#jobExecutionVetoed(org.quartz.JobExecutionContext)
     */
    @Override
    public void jobExecutionVetoed(JobExecutionContext context) {
        // TODO Auto-generated method stub

    }

    /* (non-Javadoc)
     * @see org.quartz.JobListener#jobWasExecuted(org.quartz.JobExecutionContext, org.quartz.JobExecutionException)
     */
    @Override
    public void jobWasExecuted(JobExecutionContext context,
            JobExecutionException jobException) {
//        // get all jobs that to be executed after this job is finished
//        List<String> jobToExecuteList = (List<String>) context.get("JobsToExecuteAfterKey");
//        if (jobToExecuteList.isEmpty()) {
//            return;
//        }
//        
//        for (String jobFullName : jobToExecuteList) {
//            int index = jobFullName.indexOf(".");
//            if(index < 0) {
//                continue;
//            }
//            
//            // get group name and job name
//            String groupName = jobFullName.substring(0, index);
//            String jobName = jobFullName.substring(index + 1);
//            
//            // execute job
//            logger.info(jobName + " is triggered.");
//            try {
//                context.getScheduler().triggerJob(jobName, groupName);
//            } catch (SchedulerException e) {
//                logger.error("Can not executed " +
//                		"the waiting batches because of error : " + e);
//            }
//        }

    }

}
